package com.bw.base.net

import com.blankj.utilcode.util.SPUtils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

object ReUtils {
    fun getOkHttp():OkHttpClient{
        return OkHttpClient.Builder()
            .callTimeout(30,TimeUnit.SECONDS)
            .connectTimeout(30,TimeUnit.SECONDS)
            .writeTimeout(30 ,TimeUnit.SECONDS)
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .addInterceptor {
                val builder=it.request().newBuilder()
               .addHeader("token",SPUtils.getInstance().getString("token"))
                    .addHeader("accessId","0a47f73f35dd4cf291d9b9c9e16942bd").build()
                it.proceed(builder)
            }
            .build()
    }
    fun getRetrofit():Retrofit{
        return Retrofit.Builder()
            .baseUrl(Const.BASE_URL)
            .client(getOkHttp())
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }
}